package com.huaruan.youdi.views.dialogs;

import android.app.Dialog;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.DialogFragment;
import android.view.View;
import android.widget.ScrollView;

import com.huaruan.youdi.utils.DeviceUtils;


abstract class BaseDialogFragment extends DialogFragment {

    @NonNull
    @Override
    public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
        BottomPushDialog dialog = new BottomPushDialog(getActivity())
                .isBgTranslate(isBgTranslate())
                .isBgTranslateWhenDismiss(isBgTranslateWhenDismiss())
                .contentViewResId(contentViewResId()).cancelable(cancelable());
        int height;
        if(height()==0){
            if (isFullScreen()){
                height = DeviceUtils.getDefaultDisplay().getHeight();
            } else {
                height = DeviceUtils.getDefaultDisplay().getHeight() - DeviceUtils.getStatusBarHeight();
            }
        }else{
            height = height();
        }
        dialog.height(height);
        if (scrollView() != null)
            dialog.scrollView(scrollView());
        initView(dialog.contentView(), dialog);
        return dialog;
    }

    public abstract void initView(View contentView, Dialog dialog);


    public abstract int contentViewResId();


    public Boolean cancelable(){
        return true;
    }


    public int height(){
        return 0;
    }

    /**
     * 背景是否透明（没有灰色遮罩），默认true
     */
    public Boolean isBgTranslate(){
        return true;
    }


    /**
     * 是否全屏显示，延伸到了状态栏，默认false
     */
    public Boolean isFullScreen(){
        return false;
    }

    /**
     * 是否全屏显示，在状态栏的下面，默认true
     */
    public Boolean isFullScreenNotIncludeStatusBar(){
        return true;
    }

    public Boolean isBgTranslateWhenDismiss(){
        return true;
    }

    public void dismiss(){
        if (isAdded() && !isDetached() && !isRemoving())
            getDialog().dismiss();
    }

    public ScrollView scrollView(){
        return null;
    }

}
